package com.stationbuilding.adapter.message;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.stationbuilding.R;
import com.stationbuilding.bean.QuestionFlowBean;
import com.stationbuilding.bean.TaskBean;

import java.util.List;

public class TaskListAdapter extends BaseAdapter {
    private List<QuestionFlowBean> list = null;
    private Context context;

    public TaskListAdapter(Context context, List<QuestionFlowBean> list) {
        this.context = context;
        this.list = list;
    }

    /**
     * 当ListView数据发生变化时,调用此方法来更新ListView
     *
     * @param list
     */
    public void updateListView(List<QuestionFlowBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    public int getCount() {
        return this.list.size();
    }

    public Object getItem(int position) {
        return list.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        QuestionFlowBean questionFlowBean = list.get(position);
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.message_task_item, null);
            viewHolder.handleUser = (TextView) convertView.findViewById(R.id.handle_user);
            viewHolder.date = (TextView) convertView.findViewById(R.id.date);
            viewHolder.project = (TextView) convertView.findViewById(R.id.project);
            viewHolder.type = (TextView) convertView.findViewById(R.id.type);
            viewHolder.message = (TextView) convertView.findViewById(R.id.message);
            viewHolder.read = (ImageView) convertView.findViewById(R.id.read);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.handleUser.setText(questionFlowBean.getHandleUserName());
        viewHolder.date.setText(questionFlowBean.getHandleDateStr());
        viewHolder.project.setText(questionFlowBean.getProjectName());
        viewHolder.type.setText(questionFlowBean.getQuestionType());
        viewHolder.message.setText(questionFlowBean.getHandleUserName() + questionFlowBean.getHandleStatusName() + "\"" + questionFlowBean.getQuestionName() + "\", 请查收");
        if (questionFlowBean.getStatus() == 0) {
            viewHolder.read.setVisibility(View.VISIBLE);
        } else {
            viewHolder.read.setVisibility(View.GONE);
        }
        return convertView;
    }

    final static class ViewHolder {
        ImageView profile_photo;
        TextView handleUser;
        TextView date;
        TextView project;
        TextView type;
        TextView message;
        ImageView read;
    }
}